#coding=utf-8
from pylab import *
from sttest.a_deal import *

def make_title(code, sd, ed):
    return "%s\nfrom %s to %s"%(code, sd, ed)
    
def deal_bargraph(r, graph_title, imgfn):
    #figure( figsize=(9, 7) )
    title(graph_title)
    width = 0.6 
    
    sorted_keys = sorted(r.keys())
    for i,k in zip(range(len(r)), sorted_keys):
        bar(i+0.2, float(r[k]), width=width, color='red')
        
        
    #x轴    
    locs = [i+0.5 for i in range(len(r))]
    labels = [ str(i) for i in sorted_keys ]
    xticks(locs, labels)

    #y轴
    step = 0.5
    max_value = float(max(r.values()))
    end = ( int( max_value / step ) + 2 ) * step 
    rgs = Range(0, end, step).range
    yticks(rgs)

    grid(True)
    savefig(imgfn)
